﻿@using Library
@model Library.Models.Specification
@{
    var modelCulture = Model.SpecificationCultures.SingleOrDefault(i => i.Culture == NOWCulture.CurrentCulture) ?? Model.SpecificationCultures.First();

    var specificationValues = Model.SpecificationValues.OrderByDescending(i => i.Weight);

    var selectedValue = ViewData["selectedValue"] as int?;
    
    var selectList = new List<SelectListItem>
    {
        new SelectListItem
        {
            Text = string.Empty,
            Value = "0"
        }
    };

    if (selectedValue == null)
    {
        selectList.AddRange(specificationValues.Select(sv => new SelectListItem
        {
            Text = sv.Value,
            Value = sv.Id.ToString()
        }));
    }
    else
    {
        selectList.AddRange(specificationValues.Select(sv => new SelectListItem
        {
            Selected = sv.Id == selectedValue,
            Text = sv.Value,
            Value = sv.Id.ToString()
        }));
    }
}
<tr>
    <td width="400">&nbsp;&nbsp;&nbsp; @Html.DisplayFor(m => modelCulture.Name)</td>
    <td>
        @Html.DropDownList("specification-" + Model.Id, selectList, new { @class = "form-control select2", @data_specgroupid = Model.SpecificationGroupId, @data_specid = Model.Id })
    </td>
</tr>